package br.unesp.rc.business.services.test;

import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import br.unesp.rc.rafaelt.util.ApplicationContextProvider;
import br.unesp.rc.rafaelt.util.SpringUtils;
/**
 * Abstract class for spring junit test cases.
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:app-context.xml"})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public abstract class AbstractJUnitClazz {   
	
	private static final Logger LOGGER = LoggerFactory.getLogger(AbstractJUnitClazz.class);
	
    private Long startTime;
    
    @Autowired
    private ApplicationContextProvider applicationContext;

    protected AbstractJUnitClazz() {
        super();
    }
    
    @Before
    public void initContext() {
        SpringUtils.setTestApplicationContext(applicationContext);
    }

    @Before
    public void beforeTest() {
        LOGGER.info("Starting unit test...");
        startTime = new Date().getTime();
    }

    @After
    public void afterTest() {
        LOGGER.info("Ending unit test... Took {} ms.", new Date().getTime() - startTime);
    }


}
